package com.lanou.dllo.soccernews.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.bean.CompetitionBean;
import com.lanou.dllo.soccernews.bean.RankingsEntity;
import com.lanou.dllo.soccernews.volley.GetVolleyDatasUtil;

import java.util.List;

/**
 * Created by dllo on 15/11/4.
 */
public class CompetitionAtapter extends BaseAdapter{
    List<CompetitionBean.MatchesEntity> competitionBeans ;
    private LayoutInflater mInflater;
    private Context context;

    public CompetitionAtapter(Context context) {
        mInflater = LayoutInflater.from(context);

        this.context = context;
    }
    public void addDatas(List<CompetitionBean.MatchesEntity> competitionBeans) {
//        if (this.rankingsEntities == null) {
//            this.rankingsEntities = new ArrayList<>();
//        }
//        this.rankingsEntities.clear();
        //      this.rankingsEntities.addAll(rankingsEntities);
        this.competitionBeans = competitionBeans;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return competitionBeans != null && competitionBeans.size() > 0 ? competitionBeans.size()
                : 0;
    }

    @Override
    public Object getItem(int position) {
        return competitionBeans.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        CentViewHodle hodle;
        if (convertView == null) {
            hodle = new CentViewHodle();
            convertView = mInflater.inflate(R.layout.item_competition, parent,false);

            hodle.start = (TextView) convertView.findViewById(R.id.cop_start_play);
            hodle.team_a = (TextView) convertView.findViewById(R.id.cop_a_name);
            hodle.team_b = (TextView) convertView.findViewById(R.id.cop_b_name);
            hodle.fs_a = (TextView) convertView.findViewById(R.id.cop_fs);

            hodle.a_log = (ImageView) convertView.findViewById(R.id.cop_a_log);
            hodle.b_log = (ImageView) convertView.findViewById(R.id.cop_b_log);
            convertView.setTag(hodle);
        } else {
            hodle = (CentViewHodle) convertView.getTag();
        }



        CompetitionBean.MatchesEntity matchesEntity =  competitionBeans.get(position);
        if (matchesEntity != null){
          //  Log.i("lanou", competitionBean.getRank() + "****");
            hodle.start.setText(matchesEntity.getStart_play().substring(5));
            hodle.team_a.setText(matchesEntity.getTeam_A_name());
            hodle.team_b.setText(matchesEntity.getTeam_B_name());
            hodle.fs_a.setText(matchesEntity.getFs_A()+" : "+ matchesEntity.getFs_B());


            String teamA = matchesEntity.getTeam_A_id();

            String logUrl = "http://img.dongqiudi.com/data/pic/"+teamA+".png";


            GetVolleyDatasUtil.getNetWorkImg(logUrl, hodle.a_log);

            String teamB = matchesEntity.getTeam_B_id();
            String logUrl2 = "http://img.dongqiudi.com/data/pic/"+teamB+".png";


            GetVolleyDatasUtil.getNetWorkImg(logUrl2, hodle.b_log);



        }

        return convertView;
    }

    class CentViewHodle {
        TextView start,team_a,team_b,fs_a;
        ImageView a_log,b_log;
    }
}
